/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.service.busi.wx;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.commondata.DataConvertFactory;
import com.soa.service.BaseService;
import com.soa.util.wx.TrffUtil;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 *P90005
 * 定时同步预约数据
 * @author chang
 */
@Service
public class TbyyTask extends BaseService{
    @Resource 
    private TrffUtil trffUtil;
    private org.slf4j.Logger log = LoggerFactory.getLogger(TbyyTask.class);
    @Override
    public String[] keys() {
        return null;
    }

    @Override
    public void execute(AbstractCommonData in, AbstractCommonData inhead, AbstractCommonData out, AbstractCommonData outhead) {
        List<AbstractCommonData> list = queryList("get_wtb", new Object[]{});
        //获取未同步的评价
        List<AbstractCommonData> list_pj = queryList("get_pj_wtb", new Object[]{});
        
        if(list.size()>0){
             //调用接口查询检测站信息
            AbstractCommonData abs = DataConvertFactory.getInstance();
            abs.putStringValue("serviceName", "initYyxx");
            abs.putStringValue("bs", "yy");
            abs.putArrayValue("list", list);
            AbstractCommonData resp=null;
            try {
                String res = trffUtil.Nwjkdy(abs);
                resp = DataConvertFactory.getInstanceByJson(res);
                log.debug("保存预约信息返回--------------》"+resp);
                String zt = resp.getStringValue("clzt");
                if("0".equals(zt)){//成功
                    for (int i = 0; i < list.size(); i++) {
                        String lsh = list.get(i).getStringValue("lsh");
                        update("update_yy_zt",new Object[]{"1",lsh});
                    }
                }  
            } catch (Exception e) {
                log.error("调用接口出错", e);
            }
            
            
        }
        if(list_pj.size()>0){
             //调用接口查询检测站信息
            AbstractCommonData abs = DataConvertFactory.getInstance();
            abs.putStringValue("serviceName", "initYyxx");
            abs.putStringValue("bs", "pj");
            abs.putArrayValue("list", list_pj);
            AbstractCommonData resp=null;
            try {
                String res = trffUtil.Nwjkdy(abs);
                resp = DataConvertFactory.getInstanceByJson(res);
                log.debug("保存评价信息返回--------------》"+resp);
                String zt = resp.getStringValue("clzt");
                if("0".equals(zt)){//成功
                    for (int i = 0; i < list_pj.size(); i++) {
                        String lsh = list_pj.get(i).getStringValue("lsh");
                        update("update_yy_zt",new Object[]{"2",lsh});
                    }
                }  
            } catch (Exception e) {
                log.error("调用接口出错", e);
            }
            
            
        }
        
        //调接口获取预约状态改变
         AbstractCommonData abs = DataConvertFactory.getInstance();
         abs.putStringValue("serviceName", "yyztInterface");
         AbstractCommonData resp=null;
         try {
                String res = trffUtil.Nwjkdy(abs);
                resp = DataConvertFactory.getInstanceByJson(res);
                log.debug("获取预约状态同步返回--------------》"+resp);
                List<AbstractCommonData> zt_list = resp.getArrayValue("result");
                if(zt_list.size()>0){
                    for (int i = 0; i < zt_list.size(); i++) {
                        AbstractCommonData ac = zt_list.get(i);
                        String zt = ac.getStringValue("zt");
                        String lsh= ac.getStringValue("lsh");
                           update("update_yy_yyzt", new Object[]{zt,lsh});
                    }
                }
                
 
            } catch (Exception e) {
                log.error("调用获取预约状态同步接口出错", e);
            }
    }
    
}
